package ScriptsGenericos
{
	import mx.messaging.ChannelSet;
	import mx.messaging.channels.AMFChannel;	
	 
	public class ChannelManagerPRS {
		
		private static var _channelSet:ChannelSet;	
		private static var _channelSetFed:ChannelSet;
		
		private static var _urlWebFed:String;
		
		public static function get urlWebFed():String {				
			return _urlWebFed;
		}
		
		public static function get getChannelSet():ChannelSet {
				
			if (!_channelSet || _channelSet==null ){				
				_channelSet = new ChannelSet();
			}
			return _channelSet;
		}	
		
		public static function set setChannelSet(channelSet:ChannelSet):void{
			if(channelSet)
				_channelSet = channelSet;
			else
				_channelSet = new ChannelSet();
		}
		public static function get getChannelSetFed():ChannelSet {

			if (!_channelSetFed || _channelSetFed==null ){				
				_channelSetFed = new ChannelSet();
			}
			return _channelSetFed;
		}
        public static function loadConfiguration(xml:XML):void {
        	_channelSet = new ChannelSet();
        	_channelSetFed = new ChannelSet();
        	
        	Sesion.urlServidor = xml.server;
        	
            for each (var channel:XML in xml.channel){
				if (channel.type == "amf"){
					var amfChannel:AMFChannel = new AMFChannel(channel.@id, channel.endpoint);					
					_channelSet.addChannel(amfChannel);
					Sesion._channelSet.addChannel(amfChannel);
					Sesion._amf = channel.endpoint;
				}
				if(channel.type == "amf-polling"){
					var amfChannelFed:AMFChannel = new AMFChannel(channel.@id, channel.endpoint);					
					_channelSetFed.addChannel(amfChannelFed);							
					Sesion._channelSetFed.addChannel(amfChannelFed);
					Sesion._amf_polling = channel.endpoint;
				}
			}
			
			for each (var url:XML in xml.url){			
				_urlWebFed = new String(url.urlWebFed);	
			}
			
        }
        
              
	}
}